home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 707 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  814 b 

  1. Path: newsfeed.internetmci.com!xmission!news
  2. From: macron@xmission.com (Joe Schlimgen)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How to print a enum variable's names
  5. Date: Fri, 05 Jan 1996 22:36:19 GMT
  6. Organization: XMission Internet (801 539 0900)
  7. Message-ID: <30eda78e.3109304@news.xmission.com>
  8. References: <4cjohq$k5u@lsi.lsil.com>
  9. NNTP-Posting-Host: slc12.xmission.com
  10. X-Newsreader: Forte Agent .99c/16.141
  11.  
  12. On 5 Jan 1996 17:52:58 GMT, song@lsil.com (Song Liang) wrote:
  13.  
  14. >  Suppose you have a variable foo of type "enum bar_type {CAR TRUCK VAN}", if 
  15. >you do "cout << foo", it will print either 0, 1 or 2.  Is there a simple trick
  16. >to print the names, i.e CAR, TRUCK or VAN?
  17.  
  18. enum bar_type { CAR, TRUCK, VAN };
  19. const char bar_type_string { "Car", "Truck", "Van" };
  20.  
  21. bar_type foo;
  22.  
  23. cout << bar_type_string[foo];
  24.  
  25.